<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/resources/template/template.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:p="http://primefaces.org/ui"
                xmlns:bi="http://java.sun.com/jsf/composite/bill">


    <ui:define name="content">

        <h:panelGroup >
            <h:form  >
                <p:panel  >
                    <f:facet name="header">
                        <p:outputLabel value="Inward Payment Bill"/>
                        <p:commandButton ajax="false" style="float: right;" value="Clear" action="#{bhtSummeryController.makeNull}" />                        
                        <p:commandButton ajax="false" style="float: right;" value="To Settle Bill" action="inward_final_bill"/>
                        <p:commandButton ajax="false" style="float: right;" value="Print Intrim bill" >
                            <p:printer target="intrimBill"/>
                        </p:commandButton> 


                    </f:facet>
                    <h:panelGrid columns="3" style="min-width: 100%;">
                        <p:panel header="BHT">
                            <p:autoComplete converter="dis" widgetVar="aPt" id="acPt" forceSelection="true" 
                                            value="#{bhtSummeryController.patientEncounter}"
                                            completeMethod="#{roomChangeController.completePatient2}" 
                                            var="myItem" itemValue="#{myItem}" 
                                            itemLabel="#{myItem.bhtNo}" 
                                            size="30"  >
                                <p:ajax event="itemSelect" process="acPt" update="panSearch2 tvPt sum tot intrimBill"/>
                                <p:column>
                                    <h:outputLabel value="#{myItem.bhtNo}"/>
                                </p:column>
                                <p:column>
                                    <h:outputLabel value="#{myItem.patient.person.nameWithTitle}"/>
                                </p:column>
                            </p:autoComplete>   
                            <h:panelGrid id="panSearch2" columns="2" >
                                <h:outputLabel  rendered="#{bhtSummeryController.patientEncounter!=null}" value="Name:" />
                                <h:outputLabel rendered="#{bhtSummeryController.patientEncounter!=null}" value="#{bhtSummeryController.patientEncounter.patient.person.nameWithTitle}" ></h:outputLabel>
                                <h:outputLabel  rendered="#{bhtSummeryController.patientEncounter!=null}" value="Sex" />
                                <h:outputLabel rendered="#{bhtSummeryController.patientEncounter!=null}" value="#{bhtSummeryController.patientEncounter.patient.age}" ></h:outputLabel>
                                <h:outputLabel  rendered="#{bhtSummeryController.patientEncounter!=null}" value="DOB"  />
                                <h:outputLabel rendered="#{bhtSummeryController.patientEncounter!=null}" value="#{bhtSummeryController.patientEncounter.patient.person.dob}"   >
                                    <f:convertDateTime pattern="dd/MM/yy" />
                                </h:outputLabel>
                                <h:outputLabel  rendered="#{bhtSummeryController.patientEncounter!=null}" value="Adress" />
                                <h:outputLabel rendered="#{bhtSummeryController.patientEncounter!=null}" value="#{bhtSummeryController.patientEncounter.patient.person.address}" ></h:outputLabel>
                                <h:outputLabel  rendered="#{bhtSummeryController.patientEncounter!=null}" value="Date of Admission"  />
                                <h:outputLabel rendered="#{bhtSummeryController.patientEncounter!=null}" value="#{bhtSummeryController.patientEncounter.dateOfAdmission}"   >
                                    <f:convertDateTime pattern="dd/MM/yy" />
                                </h:outputLabel>
                            </h:panelGrid>
                        </p:panel>

                        <p:panel header="Summary" id="ss">
                            <h:panelGrid columns="2" id="tot">
                                <h:outputLabel  value="Total Charges" style="font-weight: bold"/>
                                <h:outputLabel id="gtot" value="#{bhtSummeryController.grantTotal}"/>                                                      
                                <h:outputLabel value="Paid " style="font-weight: bold"/>
                                <h:outputLabel value="#{bhtSummeryController.paid}"/>
                                <h:outputLabel value="Due " style="font-weight: bold"/>
                                <h:outputLabel id="due" value="#{bhtSummeryController.due}"/>
                            </h:panelGrid>
                        </p:panel>
                        <p:panel header="Discharge">
                            <h:panelGrid columns="2">
                                <p:outputLabel value="Discharge Time"/>
                                <p:calendar value="#{bhtSummeryController.patientEncounter.dateOfDischarge}" pattern="dd MMMM yyyy hh mm ss a" >                               
                                    <f:ajax execute="@this" render="sum tvPt ss" event="dateSelect" listener="#{bhtSummeryController.checkDate}" />
                                </p:calendar> 
                                <p:commandButton ajax="false" style="float: right;" value="Disharge" action="#{bhtSummeryController.discharge}" />
                            </h:panelGrid>
                        </p:panel>

                    </h:panelGrid>
                    <h:panelGrid id="sum" columns="2">
                        <p:dataTable value="#{bhtSummeryController.chargeItemTotals}" style="max-width: 25%;" var="c">
                            <p:column >
                                <h:outputLabel value="#{c.inwardChargeType}"/>
                            </p:column>
                            <p:column >
                                <h:outputLabel value="#{c.total}"/>
                            </p:column>
                        </p:dataTable>                       

                        <p:tabView  id="tvPt" style="min-height: 75%;"  >
                            <p:ajax event="tabChange"  process="@this" />
                            <p:tab id="tabNewPt" title="Room Detail" >
                                <p:dataTable value="#{bhtSummeryController.patientRoom}" var="rm">
                                    <p:column headerText="Room Name">
                                        #{rm.patientRoom.roomFacilityCharge.name}
                                    </p:column>                                                                          
                                    <p:column headerText="Admitted At">
                                        <h:outputLabel value="#{rm.patientRoom.admittedAt}">
                                            <f:convertDateTime pattern="dd MMMM yyyy hh mm ss a"/>
                                        </h:outputLabel>
                                    </p:column>
                                    <p:column headerText="Discharged At">
                                        <h:outputLabel value="#{rm.patientRoom.dischargedAt}">
                                            <f:convertDateTime pattern="dd MMMM yyyy hh mm ss a"/>
                                        </h:outputLabel>
                                    </p:column>

                                    <p:column headerText="Room Charge">
                                        #{rm.chargeTot}
                                    </p:column> 
                                    <p:column headerText="Maintain Charge">
                                        #{rm.maintananceTot}
                                    </p:column>    
                                    <p:column headerText="MO Charge">
                                        #{rm.moChargeTot}
                                    </p:column>                                        
                                    <p:column headerText="Nursing Charge">
                                        #{rm.nursingTot}
                                    </p:column> 
                                    <p:column headerText="Linen Charge">
                                        #{rm.linenTot}
                                    </p:column> 
                                </p:dataTable>
                            </p:tab>

                            <p:tab id="tabSer" title="Service Detail"  >
                                <p:dataTable value="#{bhtSummeryController.service}" var="ser">
                                    <p:column headerText="Name">
                                        #{ser.item.name}
                                    </p:column>
                                    <p:column headerText="Cost">
                                        #{ser.netValue}
                                    </p:column>
                                    <p:column headerText="Added Date">
                                        <h:outputLabel value="#{ser.createdAt}">
                                            <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss a"/>
                                        </h:outputLabel>
                                    </p:column>
                                    <p:column headerText="Added Time">
                                        <h:outputLabel value="#{ser.createdAt}">
                                            <f:convertDateTime pattern="hh mm ss a"/>
                                        </h:outputLabel>
                                    </p:column>
                                    <p:column headerText="Added User">
                                        <h:outputLabel value="#{ser.creater.webUserPerson.name}">
                                            <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss a"/>
                                        </h:outputLabel>
                                    </p:column>
                                    <p:column>
                                        <h:commandLink action="inward_bill_reprint" value="Remove">
                                            <h:outputLabel  ></h:outputLabel>
                                            <f:setPropertyActionListener value="#{ser.bill}" target="#{inwardSearch.bill}"/>
                                        </h:commandLink>
                                    </p:column>

                                </p:dataTable>
                            </p:tab>

                            <p:tab id="tabTimed" title="Timed Service Detail"  >
                                <p:calendar value="#{bhtSummeryController.toTime}" pattern="dd MMMM yyyy hh mm ss a" >    
                                </p:calendar> 
                                <p:dataTable value="#{bhtSummeryController.patientItems}" var="ti">
                                    <p:column headerText="Service Name">
                                        #{ti.item.name}
                                    </p:column>
                                    <p:column headerText="Start Time">
                                        <h:outputLabel value="#{ti.fromTime}">
                                            <f:convertDateTime pattern="dd MMMM yyyy hh mm ss a"/>
                                        </h:outputLabel>
                                    </p:column>
                                    <p:column headerText="Total">
                                        #{ti.serviceValue}
                                    </p:column>
                                    <p:column headerText="Stopped Time">
                                        <h:outputLabel value="#{ti.toTime}">
                                            <f:convertDateTime pattern="dd MMMM yyyy hh mm ss a"/>
                                        </h:outputLabel>
                                    </p:column>
                                    <p:column >
                                        <p:commandButton value="Finalize" disabled="#{ti.finalize}" ajax="false" action="#{bhtSummeryController.finalizeService}">
                                            <f:setPropertyActionListener value="#{ti}" target="#{bhtSummeryController.tmpPI}"/>
                                        </p:commandButton>
                                    </p:column>
                                </p:dataTable>
                            </p:tab>

                            <p:tab id="tabPro" title="Professional Fee"  >
                                <p:dataTable value="#{bhtSummeryController.profesionallFee}" var="pf">
                                    <p:column headerText="Name">
                                        #{pf.staff.person.nameWithTitle}
                                    </p:column>
                                    <p:column headerText="Fee Value">
                                        #{pf.feeValue}
                                    </p:column>
                                    <p:column headerText="Fee At">
                                        <h:outputLabel value="#{pf.feeAt}">
                                            <f:convertDateTime pattern="dd MMMM yyyy hh mm a"/>
                                        </h:outputLabel>
                                    </p:column>
                                    <p:column headerText="Added Time">
                                        <h:outputLabel value="#{pf.createdAt}">
                                            <f:convertDateTime pattern="hh mm a"/>
                                        </h:outputLabel>
                                    </p:column>
                                    <p:column headerText="Added User">
                                        <h:outputLabel value="#{pf.creater.webUserPerson.name}">
                                            <f:convertDateTime pattern="dd MM yyyy hh mm a"/>
                                        </h:outputLabel>
                                    </p:column>
                                    <p:column>
                                        <h:commandLink action="inward_bill_reprint" value="Remove">
                                            <h:outputLabel  ></h:outputLabel>
                                            <f:setPropertyActionListener value="#{pf.bill}" target="#{inwardSearch.bill}"/>
                                        </h:commandLink>
                                    </p:column>

                                </p:dataTable>
                            </p:tab>

                            <p:tab id="tabP" title="Payments"  >
                                <p:dataTable value="#{bhtSummeryController.paymentBill}" var="p">
                                    <p:column headerText="Paid At">                                            
                                        <h:outputLabel value="#{p.billTime}">
                                            <f:convertDateTime pattern="dd MMMM yyyy hh mm a"/>
                                        </h:outputLabel>
                                    </p:column>
                                    <p:column headerText="Value">
                                        #{p.netTotal}
                                    </p:column>

                                </p:dataTable>
                            </p:tab>

                        </p:tabView>

                    </h:panelGrid>
                </p:panel>


                <p:panel id="intrimBill"  >
                    <bi:inwardBill controller="#{bhtSummeryController}" 
                                   isIntrim="true"
                                   item="#{bhtSummeryController.chargeItemTotals}"
                                   patientEncounter="#{bhtSummeryController.patientEncounter}"
                                   bill="#{bhtSummeryController.current}"/>


                </p:panel>

            </h:form>

        </h:panelGroup>



    </ui:define>

</ui:composition>
